Repository navigation
Keep backslash-escaped pipes inside table cells - #818
Merged
Merged
Conversation
mattr-
reviewed
Oct 7, 2026
Comment on lines
+2279
to
+2284
| static int | ||
| is_table_delimiter(uint8_t *data, size_t i) | ||
| { | ||
| return data[i] == '|' && (i == 0 || data[i - 1] != '\\'); | ||
| } | ||
|
|
Collaborator
There was a problem hiding this comment.
Appreciate this abstraction!
| parse_inline(cell_work, rndr, cell_text->data, cell_text->size); | ||
| rndr->cb.table_cell(row_work, cell_work, col_data[col] | header_flag, rndr->opaque); | ||
|
|
||
| rndr_popbuf(rndr, BUFFER_SPAN); |
Collaborator
There was a problem hiding this comment.
Was this additional rndr_popbuf call intentional? It's not clear why we would need two calls.
Contributor
Author
There was a problem hiding this comment.
@mattr- Yes, this is intentional! Each cell now takes two span buffers, cell_work and cell_text, so it needs two pops. I added a comment to each pop to make that a bit more clear.
Redcarpet split table rows at every pipe, including `\|`. Per GFM, `\|` belongs to the cell, even inside a code span. A split inside a code span ended the span early, so Redcarpet parsed the rest of the cell as Markdown, links included. Skip `\|` when splitting cells and counting header columns, and remove the backslash before inline parsing, as `cmark-gfm` does. Fixes vmg#477.
flavorjones
force-pushed
the
card-604-table-escaped-pipes
branch
from
October 8, 2026 18:11
2b6fbae to
b3c4099
Compare
mattr-
approved these changes
Oct 8, 2026
mattr-
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Per the GitHub Flavored Markdown spec, a table cell can contain a pipe written as
\|, even inside a code span (example 200).parse_table_rowinext/redcarpet/markdown.csplits a row at every|, so the cell ends at the escaped pipe. Inside a code span, the split also ends the span early, and Redcarpet parses the rest of the cell as Markdown. Given the input:Redcarpet previously produced these cells:
Now it produces the cells a compliant parser emits, matching
cmark-gfm:The table parser removes the backslash before inline parsing, because the CommonMark spec treats backslashes inside a code span as literal text.
parse_table_headeralso counted\|as a column separator, so a header containing one gained an extra column and Redcarpet rendered the whole table as a paragraph.parse_table_headernow skips\|, too.A pipe after any backslash, including an escaped one (
\\|), stays in the cell, and only the backslash directly before the pipe is removed, ascmark-gfm'sunescape_pipesdoes. This rule deliberately differs from the backslash-parity rule #817 added for link labels. A tool that escapes every|in a code span as\|turns code containing\|into`\\|`, and only thecmark-gfmrule keeps that code span in one piece.Fixes #477.